var async=require('async');

var concurrencyCount=0;

function fetchUrl(url,callback){
  concurrencyCount++;
  var delay=parseInt((Math.random()*10000000)%2000,10);
  console.log('现在的并发数是:'+concurrencyCount+';抓取的链接是：'+url+';耗时'+delay+'毫秒');
  setTimeout(function(){
    concurrencyCount--;
    callback(null,url+' html content');
  },delay)

}

var urls=[];
for(var i=0;i<30;i++){
  urls.push('baseUrl__'+i);
}

async.mapLimit(urls,5,function(url,callback){
  fetchUrl(url,callback);

},function(err,result){
  console.log('finished');
  console.log(result);
})